const request = (config) => {
    // 处理 apiUrl
    if (!config.address) {
        // config.url = 'https://hezi-api.threecats.cn/api/' + config.url;
        config.url = 'http://127.0.0.1:8085/' + config.url;
        // config.url = 'http://192.168.1.9:1323/api/' + config.url;
        //    config.url = 'http://192.168.31.135:1323/api/' + config.url;
    }


    if (!config.data) {
        config.data = {};
    }

    let promise = new Promise(function (resolve, reject) {
        config.header = {
            'Authorization': "Bearer " + uni.getStorageSync('token'),
            'Content-Type': 'application/x-www-form-urlencoded'
        }

        uni.request(config).then(responses => {
            if (responses[0]) {
                console.log("网络超时")
                console.log(responses)
                reject({
                    message: "网络超时"
                });
                return
            }
            if (responses.statusCode == 401) {
                console.log("token 失效")
                let token = ""
                uni.setStorageSync('token', token)
                uni.switchTab({
                    url: '/pages/login/login'
                })
            }
            resolve(responses.data);
        });
    }).catch(error => {
        reject(error)
    })

    return promise;
};


export default request;
